﻿using BEPUutilities;
using FixMath.NET;
using GameConfig;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GameLogic
{
    public class WeaponData
    {
        GameConfig.Weapon m_Cfg;
        Fix64 m_Angle = 0;
        int m_ShotCoolingFrame = 0;
        private int m_CfgID = -1; 
        public bool IsShotCooling { get { return m_ShotCoolingFrame < ShotCoolingFrameMax; } }
        public int ShotCoolingFrame { get { return m_ShotCoolingFrame; }set { m_ShotCoolingFrame = value; } }
        public int ShotCoolingFrameMax { get { return 30 / m_Cfg.ShotFrequency; } }
        public Fix64 Angle { get => m_Angle; set => m_Angle = value; }
        public BEPUutilities.Quaternion Rotation { get { return BEPUutilities.Quaternion.CreateFromAxisAngle(new BEPUutilities.Vector3(0, 0, 1), MathHelper.ToRadians(Angle)); } }
        public BEPUutilities.Vector3 Direction
        {
            get
            {
                var rot = Rotation;
                var curDir = new BEPUutilities.Vector3();
                var upDir = new BEPUutilities.Vector3(0, 1, 0);
                BEPUutilities.Quaternion.Transform(ref upDir, ref rot, out curDir);
                return curDir;
            }
        }
        public Weapon Cfg { get => m_Cfg; set => m_Cfg = value; }

        public static WeaponData Create(int cfgID)
        {
            WeaponData data = new WeaponData();
            data.m_CfgID = cfgID;
            data.Init(cfgID);
            //data.m_InstanceID = instanceID;
            return data;
        }
        public void Init(int cfgID)
        {
            m_Cfg = ConfigSystem.Instance.Tables.TbWeapon.GetOrDefault(cfgID);
        }

        public string GetIdentityStr()
        {
            return "Weapon" + m_CfgID;
        }
    }
}
